using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class InventoryBLL
    {
        InventoryDal inventoryDal = new InventoryDal();

        public List<InventoryReturnModel> GetList(InventorySearchModel ssm, Pagination page, TokenModel token)
        {
            return inventoryDal.GetList(ssm, page, token);
        }

        public Guid SaveInventory(Inventory inventory, TokenModel token)
        {
            Guid InventoryID = inventory.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (inventory != null && inventory.id != Guid.Empty)
            {
                //修改
                isSuccess = inventoryDal.UpdateModel(inventory) > 0;

            }
            else
            {
                //新增
                inventory.addTime = curTime;
                inventory.id = Guid.NewGuid();
                Inventory inventoryInfo = inventoryDal.AddModel(inventory);
                InventoryID = inventoryInfo.id;

            }

            return InventoryID;
        }

        public InventoryReturnModel GetInventoryByID(Guid id)
        {
            InventoryReturnModel inventoryModel = new InventoryReturnModel();
            Inventory inventory = inventoryDal.FindModel(c => c.id == id);
            inventoryModel = ClassHelper.ParentCopyToChild<Inventory, InventoryReturnModel>(inventory);

            return inventoryModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return inventoryDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
